package com.yanqu.road.server.cmd.activity.yearMaster;

import com.yanqu.road.entity.activity.yearMaster.UserYearMasterDataResult;
import com.yanqu.road.logic.pb.YearMasterPb;
import com.yanqu.road.pb.yearMaster.YearMasterProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.yearMaster.YearMasterModule;
import com.yanqu.road.server.manger.activity.yearMaster.YearMasterMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_YEAR_MASTER_GET_INFO, desc = "瑞兽降福进入界面信息拉取")
public class YearMasterGetInfoCmd extends AbstractCommand {

    private UserYearMasterDataResult userYearMasterDataResult;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
       // YearMasterProto.YearMasterGetBaseInfoReqMsg req = YearMasterProto.YearMasterGetBaseInfoReqMsg.parseFrom(packet.getBytes());
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        userYearMasterDataResult = player.getModule(YearMasterModule.class).getYearMasterInfo();
    }

    @Override
    public void sendData(GamePlayer player) {
        YearMasterProto.YearMasterGetBaseInfoRspMsg.Builder resp = YearMasterProto.YearMasterGetBaseInfoRspMsg.newBuilder();
        resp.setRet(userYearMasterDataResult.getRet());
        if (userYearMasterDataResult.getUserYearMasterData() != null) {
            resp.setBaseInfo(YearMasterPb.parseYearMasterBaseRespMsg(YearMasterMgr.getYearMasterBoss(), userYearMasterDataResult.getUserYearMasterData(),YearMasterMgr.getYearMasterActivityConfig().getHighOpenScore()));
            resp.setScore(userYearMasterDataResult.getUserYearMasterData().getScore());

            resp.setUserRank(YearMasterMgr.getYearMasterUserRank(player.getUserId(),0));
        }

        player.sendPacket(ClientProtocol.U_YEAR_MASTER_GET_INFO, resp);
    }
}
